//封装request对象，
import axios from 'axios';
import router from '../router/router'
import notification from './notification';
const service = axios.create({
        baseURL: 'http://127.0.0.1:8360'
    })
    //发送请求前的统一处理
service.interceptors.request.use(config => {
        config.headers.jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsb2dpbiI6eyJpZCI6MX0sImlhdCI6MTczMDg3MzMxMX0.vf_DD0PcXn7R6SwABui6f40WUgn2_NmtKO0JZqFIFjk'
        return config
    })
    //响应对象的统一处理
service.interceptors.response.use(
    response => {
        const { errno, data, errmsg } = response.data
        if (errno === 0) {
            if (errmsg != 0) {
                notification({
                    message: errmsg,
                    type: 'success'
                })
            }
            return data || true
        }
        notification({
            message: errmsg,
            type: 'error'
        })
        if (errno === 2) {
            router.push({ name: 'login' })
        }
        return false
    }
)
export default service